import { TestLRU } from "./TestLRU";

console.log("hello world!");

function countValidWords(sentence: string): number {
    let worlds: string[] = sentence.split(' ');
    console.log('worlds = ', worlds);
    let count = 0;
    for(let i = 0;i < worlds.length; i++){
        let wd = worlds[i];
        if(wd === ''){
            continue;
        }
        let isValid = true;
        for(let j = 0; j< wd.length; j++){
            if(wd[j].charCodeAt(0) >= '0'.charCodeAt(0) && wd[j].charCodeAt(0) <= '9'.charCodeAt(0)){
                isValid = false;
                break;
            }
            if(wd[j] === '-'){
                if(j === wd.length -1 || j === 0){
                    isValid = false;
                    break;
                }
                if(wd[j-1].charCodeAt(0) < 'a'.charCodeAt(0) || wd[j-1].charCodeAt(0) > 'z'.charCodeAt(0) || wd[j+1].charCodeAt(0) < 'a'.charCodeAt(0) || wd[j+1].charCodeAt(0) > 'z'.charCodeAt(0)){
                    isValid = false;
                    break;
                }
            }
            if(wd[j] === ',' || wd[j] === '!' || wd[j] === '.'){
                if(j!== wd.length -1){
                    isValid = false;
                    break;
                }
            }
        }
        if(isValid) {
            count++;
        }

    }
    return count;
};

function nextBeautifulNumber(n: number): number {
    let numMap: Map<number, number> = new Map();

    const getNums = (value:number) =>{
        for(let i = 0; i < 10; i++){
            numMap.set(i, 0);
        }
        while(value != 0){
            let remainder = value %10;
            value = Math.floor(value/10);
            console.log('value ', value, ' remainder ', remainder);
            let count = numMap.get(remainder);
            numMap.set(remainder, count+1);
        }
    }
    let num = n + 1;
    let max = Math.pow(10,6);
    while(true){
        getNums(num);
        console.log('numMap ', numMap);
        let isAns = true;
        for(const [k, v] of numMap.entries()){
            if(v!==0 && k !== v){
                isAns = false;
                break;
            }
        }
        if(isAns){
            return num;
        }
        num++;
    }
    true
    return num;
};

// let sentence = "cat and  dog";
// console.log('count = ',countValidWords(sentence));

// console.log('answer = ', nextBeautifulNumber(1));

TestLRU.test();